#include <algorithm>
#include <cstdio>

#define sft 10001

const int N = 5005, M = 20005;
int n, ans, max;

struct Node {
  int val, cnt, tag;
} tr[M << 2];

struct Rect {
  int x1, y1, x2, y2;
} rec[N];

struct Event {
  Event() = default;
  Event(int x, int y1, int y2, int v) : x(x), y1(y1), y2(y2), v(v) {}
  int x, y1, y2, v;
  inline bool operator<(const Event &rhs) const {
    return x == rhs.x ? v > rhs.v : x < rhs.x;
  }
} eve[N << 1];

inline void pushdown(int x) {
  static int ls, rs;
  if (tr[x].tag) {
    ls = x << 1, rs = x << 1 | 1;
    tr[ls].tag += tr[x].tag;
    tr[rs].tag += tr[x].tag;
    tr[ls].cnt += tr[x].tag;
    tr[rs].cnt += tr[x].tag;
    tr[x].tag = 0;
  }
}

inline void pushup(int x, int l, int r) {
  static int ls, rs;
  ls = x << 1, rs = x << 1 | 1;
  if (tr[ls].cnt == tr[rs].cnt) {
    tr[x].cnt = tr[ls].cnt;
    tr[x].val = tr[ls].val + tr[rs].val;
  } else if (tr[ls].cnt < tr[rs].cnt) {
    tr[x].cnt = tr[ls].cnt;
    tr[x].val = tr[ls].val;
  } else {
    tr[x].cnt = tr[rs].cnt;
    tr[x].val = tr[rs].val;
  }
}

void build(int x, int l, int r) {
  tr[x].tag = 0;
  if (l == r) return tr[x].val = 1, tr[x].cnt = 0, void();
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  pushup(x, l, r);
}

void modify(int x, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) return tr[x].tag += v, tr[x].cnt += v, void();
  int mid = (l + r) >> 1;
  pushdown(x);
  if (L <= mid) modify(x << 1, l, mid, L, R, v);
  if (mid < R) modify(x << 1 | 1, mid + 1, r, L, R, v);
  pushup(x, l, r);
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P1856 矩形周长.in", "r", stdin);
  freopen("P1856 矩形周长.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d%d", &rec[i].x1, &rec[i].y1, &rec[i].x2, &rec[i].y2);
    max = std::max(
        max, std::max(rec[i].x1, std::max(rec[i].y1, std::max(rec[i].y2, rec[i].x2))));
    rec[i].x1 += sft, rec[i].y1 += sft, rec[i].y2 += sft, rec[i].x2 += sft;
    eve[i] = Event(rec[i].x1, rec[i].y1, rec[i].y2, 1);
    eve[i + n] = Event(rec[i].x2, rec[i].y1, rec[i].y2, -1);
  }

  build(1, 1, max + sft);
  n <<= 1;
  std::sort(eve + 1, eve + n + 1);
  for (int i = 1, ori; i <= n; ++i) {
    ori = tr[1].val;
    modify(1, 1, max + sft, eve[i].y1, eve[i].y2 - 1, eve[i].v);
    ans += std::abs(tr[1].val - ori);
  }

  n >>= 1;
  for (int i = 1; i <= n; ++i) {
    eve[i] = Event(rec[i].y1, rec[i].x1, rec[i].x2, 1);
    eve[i + n] = Event(rec[i].y2, rec[i].x1, rec[i].x2, -1);
  }

  build(1, 1, max + sft);
  n <<= 1;
  std::sort(eve + 1, eve + n + 1);
  for (int i = 1, ori; i <= n; ++i) {
    ori = tr[1].val;
    modify(1, 1, max + sft, eve[i].y1, eve[i].y2 - 1, eve[i].v);
    ans += std::abs(tr[1].val - ori);
  }

  printf("%d", ans);
  return 0;
}